package com.spic.business.train.examDetail.service.impl;

import com.spic.business.common.datascope.anotation.BusinessDataScope;
import com.spic.business.train.examDetail.domain.TrainExamDetail;
import com.spic.business.train.examDetail.mapper.TrainExamDetailMapper;
import com.spic.business.train.examDetail.service.ITrainExamDetailService;
import com.spic.business.train.prepare.domain.TrainExamUserState;
import com.spic.business.train.prepare.mapper.TrainExamUserStateMapper;
import com.spic.common.core.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 考试详情记录Service业务层处理
 *
 * @author spic
 * @date 2022-07-13
 */
@Service
public class TrainExamDetailServiceImpl implements ITrainExamDetailService
{
    @Autowired
    private TrainExamDetailMapper trainExamDetailMapper;
    @Autowired
    private TrainExamUserStateMapper trainExamUserStateMapper;


    /**
     * 查询考试详情记录
     *
     * @param id 考试详情记录主键
     * @return 考试详情记录
     */
    @Override
    public TrainExamDetail selectTrainExamDetailById(Long id)
    {
        return trainExamDetailMapper.selectTrainExamDetailById(id);
    }

    /**
     * 查询考试详情记录列表
     *
     * @param trainExamDetail 考试详情记录
     * @return 考试详情记录
     */
    @BusinessDataScope(menuPath = "business/train/examrecord/index")
    @Override
    public List<TrainExamDetail> selectTrainExamDetailList(TrainExamDetail trainExamDetail)
    {
        return trainExamDetailMapper.selectTrainExamDetailList(trainExamDetail);
    }

    @Override
    public List<TrainExamDetail> selectPaperList(TrainExamDetail trainExamDetail)
    {
        return trainExamDetailMapper.selectPaperList(trainExamDetail);
    }

    /**
     * 新增考试详情记录
     *
     * @param trainExamDetail 考试详情记录
     * @return 结果
     */
    @Override
    public int insertTrainExamDetail(TrainExamDetail trainExamDetail)
    {
        trainExamDetail.setCreateTime(DateUtils.getNowDate());
        return trainExamDetailMapper.insertTrainExamDetail(trainExamDetail);
    }

    /**
     * 修改考试详情记录
     *
     * @param trainExamDetail 考试详情记录
     * @return 结果
     */
    @Override
    public int updateTrainExamDetail(TrainExamDetail trainExamDetail)
    {
        return trainExamDetailMapper.updateTrainExamDetail(trainExamDetail);
    }

    /**
     * 批量删除考试详情记录
     *
     * @param ids 需要删除的考试详情记录主键
     * @return 结果
     */
    @Override
    public int deleteTrainExamDetailByIds(Long[] ids)
    {
        return trainExamDetailMapper.deleteTrainExamDetailByIds(ids);
    }

    @Override
    public int examNote(List<TrainExamUserState> list)
    {
        if(list !=null && list.size()>0){
            for(TrainExamUserState item:list){
                trainExamUserStateMapper.updateById(item);
            }
        }
        return 1;
    }



    /**
     * 删除考试详情记录信息
     *
     * @param id 考试详情记录主键
     * @return 结果
     */
    @Override
    public int deleteTrainExamDetailById(Long id)
    {
        return trainExamDetailMapper.deleteTrainExamDetailById(id);
    }
}
